package org.gp.core.web;

import com.alibaba.fastjson.JSON;
import org.gp.core.entity.Comment;
import org.gp.core.entity.dto.ResponseDTO;
import org.gp.core.service.ICommentService;
import org.gp.core.web.param.CommentParam;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 评论表  前端控制器
 * </p>
 *
 * @author LuoLiang
 * @since 2017-02-27
 */
@RestController
@RequestMapping("/comment")
public class CommentController {
    @Resource
    private ICommentService commentService;

    @RequestMapping(value = "commentactivitytest", method = RequestMethod.POST)
    public String commentActivityTest(CommentParam param) {
        ResponseDTO dto = commentService.commentActivity(1, param.getActivityId(), param.getScore(), param.getContent());

        return JSON.toJSONString(dto);
    }

    @RequestMapping(value = "commentactivity", method = RequestMethod.POST)
    public String commentActivity(@CookieValue("USERID") Integer userId, CommentParam param) {
        ResponseDTO dto = commentService.commentActivity(userId, param.getActivityId(), param.getScore(), param.getContent());

        return JSON.toJSONString(dto);
    }

    @RequestMapping(value = "activitycommentlist", method = RequestMethod.GET)
    public String activityCommentList(String activityId) {
        ResponseDTO<List<Comment>> dto = commentService.getActivityCommentList(activityId);

        return JSON.toJSONString(dto);
    }
}
